import React, { Component } from 'react'
import eventProxy  from '../until/eventProxy.js'

class CustomTextInput extends React.Component {
  constructor(props) {
    super(props);
    // 创建 ref 存储 textInput DOM 元素
    this.textInput = React.createRef();
    this.focusTextInput = this.focusTextInput.bind(this);
    this.state = {
    	 errMsg: null,
    	 num:0,
       value: this.props.defaultValue || '',
    }
  }
   change= key => e=> {
   	 console.log(key)
   //	 console.log(e)
     //   const value = e.target.value;
    //    this.setState({value: value});
        
   }
   componentDidMount(){
//		setTimeout(function(){
//			
//	  			eventProxy.trigger('msg','5555');
//		},2000)
		setTimeout(()=>{
			
	  				this.setState({
					num:this.state.num +2
				})
		})

		this.setState({
			num:this.state.num+3
		})
  }
  focusTextInput() {
    // 直接使用原生 API 使 text 输入框获得焦点
    // 注意：通过 "current" 取得 DOM 节点
    this.textInput.current.focus();
  }
  pts(){
  	 console.log("jfkdlj")
  }
  getValue(){
  	let {value} = this.state
  	return value
  }
  render() {
    // 告诉 React 我们想把 <input> ref 关联到构造器里创建的 `textInput` 上
    
    console.log(this.state.num)
    return (
      <div>
        <input
          type="text" onChange={this.change('sss')}
          ref={this.textInput} value={this.state.value} />

          
        <input
          type="button"
          value="Focus the text input"
          onClick={this.focusTextInput}
        />
      </div>
    );
  }
}

export default CustomTextInput